package com.project.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.project.dao.IMenuDao;
import com.project.dao.bean.Menu;
import com.project.webapp.form.backend.basic.MenuForm;
import com.project.webapp.form.front.preSchool.PreSchoolForm;

public class MenuDaoImpl extends BaseDaoImpl implements IMenuDao {

	@Override
	public String save(MenuForm menuForm) throws Exception {
		// 新增
		UUID uuid = UUID.randomUUID();
		menuForm.setMenuId(uuid.toString());
		this.getSqlMapClient().insert("saveMenu", menuForm);
		return uuid.toString();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Menu> findMenuByPg(MenuForm menuForm) throws Exception {
		List<Menu> list = this.queryWithPg("queryMenuByPg", menuForm);
		return list;
	}

	@Override
	public Integer findCount(MenuForm menuForm) throws Exception {
		Integer i = (Integer) this.getSqlMapClient().queryForObject(
				"countQueryMenuByPg", menuForm);
		return i;
	}

	@Override
	public void delete(MenuForm menuForm) throws Exception {
		this.getSqlMapClient().update("deleteMenu", menuForm);
	}

	@Override
	public void update(MenuForm menuForm) throws Exception {
		// 修改
		this.getSqlMapClient().update("updateMenu", menuForm);
	}

	@Override
	public List<Menu> findMenuForTree() throws Exception {
		List<Menu> list = this.getSqlMapClient()
				.queryForList("findMenuForTree");
		return list;
	}

	@Override
	public List<Menu> getMenuByCondition(PreSchoolForm preSchoolForm)
			throws Exception {
		List<Menu> list = this.getSqlMapClient().queryForList(
				"getMenuByCondition");
		return list;
	}

	@Override
	public List<Menu> getDescendantMenuByAncestorCodeAndSeq(
			String ancestorCode, String seq) throws Exception {
		// TODO Auto-generated method stub
		Map<String, String> map = new HashMap<String, String>();
		map.put("menuCode", ancestorCode);
		map.put("seq", seq);
		List<Menu> list = this.getSqlMapClient().queryForList(
				"getDescendantMenuByAncestorCodeAndSeq", map);
		return list;
	}

	@Override
	public void updateIsShow(String menuId, String showSort) throws Exception {
		// TODO Auto-generated method stub
		Map<String, String> map = new HashMap<String, String>();
		map.put("menuId", menuId);
		map.put("showSort", showSort);
		this.getSqlMapClient().update("updateIsShow", map);
	}

	@Override
	public void updateIsShowToUnShow() throws Exception {
		// TODO Auto-generated method stub
		this.getSqlMapClient().update("updateIsShowToUnShow");
	}

	@Override
	public List<Menu> getMenuForCourse(String menuCode) throws Exception {
		// TODO Auto-generated method stub
		Map<String, String> map = new HashMap<String, String>();
		map.put("menuCode", menuCode);
		return this.getSqlMapClient().queryForList("getMenuForCourse", map);
	}

}
